/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ExportModelForm.java
 *
 * Created on Jan 27, 2013, 4:54:22 PM
 */
package sea;
import sea.util.PublicParam;
import javax.swing.JOptionPane;
import sea.util.SimHyAHelper;

/**
 *
 * @author luca
 */
public class ExportModelForm extends javax.swing.JDialog {

    /** Creates new form ExportModelForm */
    public ExportModelForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        exportButtonGroup = new javax.swing.ButtonGroup();
        jLabel5 = new javax.swing.JLabel();
        modelvarNameText = new javax.swing.JTextField();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        sbmlButton = new javax.swing.JRadioButton();
        matlabButton = new javax.swing.JRadioButton();
        matlablnButton = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        filenameTextField = new javax.swing.JTextField();
        confirmButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Export Model");
        setName("ExportModelForm"); // NOI18N
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jLabel5.setText("Model Variable");
        jLabel5.setName("jLabel5"); // NOI18N

        modelvarNameText.setEditable(false);
        modelvarNameText.setToolTipText("the variable containing model data.");
        modelvarNameText.setEnabled(false);
        modelvarNameText.setName("modelvarNameText"); // NOI18N

        jLayeredPane1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLayeredPane1.setName("jLayeredPane1"); // NOI18N

        jLabel1.setText("Export to");
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setBounds(10, 10, 80, 16);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        exportButtonGroup.add(sbmlButton);
        sbmlButton.setSelected(true);
        sbmlButton.setText("SBML");
        sbmlButton.setName("sbmlButton"); // NOI18N
        sbmlButton.setBounds(80, 10, 64, 23);
        jLayeredPane1.add(sbmlButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        exportButtonGroup.add(matlabButton);
        matlabButton.setText("Matlab m file");
        matlabButton.setName("matlabButton"); // NOI18N
        matlabButton.setBounds(80, 40, 114, 23);
        jLayeredPane1.add(matlabButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        exportButtonGroup.add(matlablnButton);
        matlablnButton.setText("Matlab m file (linear noise)");
        matlablnButton.setName("matlablnButton"); // NOI18N
        matlablnButton.setBounds(80, 70, 220, 23);
        jLayeredPane1.add(matlablnButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setText("File Name");
        jLabel2.setName("jLabel2"); // NOI18N

        filenameTextField.setName("filenameTextField"); // NOI18N

        confirmButton.setText("Confirm");
        confirmButton.setName("confirmButton"); // NOI18N
        confirmButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.setName("cancelButton"); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jLabel5)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(modelvarNameText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(cancelButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(confirmButton))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(filenameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLayeredPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(modelvarNameText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(filenameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(25, 25, 25)
                .add(jLayeredPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 34, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(confirmButton)
                    .add(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
    modelvarNameText.setText(PublicParam.CurrentModelVariableName);
}//GEN-LAST:event_formComponentShown

private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
    String f = this.filenameTextField.getText();
    if (f.length() == 0)
        JOptionPane.showMessageDialog(this, "Filename has to be specified.", "Error", JOptionPane.ERROR_MESSAGE);
    else {
        String s = "save(";
        s += "$" + this.modelvarNameText.getText() + ", ";
        s += "file=" + f + ", ";
        if (this.sbmlButton.isSelected())
            s+= "sbml";
        else if (this.matlabButton.isSelected())
            s+= "matlab";
        else if (this.matlablnButton.isSelected())
            s+= "matlab.ln";
        s += ")";
        PublicParam.SimHyACommandExpression = s;
        PublicParam.CommandTypeName = "save";
        SimHyAHelper.executeCommand();
        this.dispose();
    }
    
    
}//GEN-LAST:event_confirmButtonActionPerformed

private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
    this.dispose();
}//GEN-LAST:event_cancelButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ExportModelForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ExportModelForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ExportModelForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ExportModelForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ExportModelForm dialog = new ExportModelForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton confirmButton;
    private javax.swing.ButtonGroup exportButtonGroup;
    private javax.swing.JTextField filenameTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JRadioButton matlabButton;
    private javax.swing.JRadioButton matlablnButton;
    private javax.swing.JTextField modelvarNameText;
    private javax.swing.JRadioButton sbmlButton;
    // End of variables declaration//GEN-END:variables
}
